package jstl;

import java.io.IOException;
import java.util.List;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.TagSupport;

import org.apache.log4j.Logger;

import db.dao.DictionariesDAO;
import db.dao.LanguagesDAO;
import db.dto.DictionariesDTO;
import db.dto.LanguagesDTO;

public class ListDictionaries extends TagSupport{

	@Override
	public int doStartTag() throws JspException {
		Logger LOG = Logger.getLogger("ListDictionaries");
		JspWriter out = pageContext.getOut();
		DictionariesDAO dictDAO = new DictionariesDAO();
		LanguagesDAO lanDAO = new LanguagesDAO();
		List<DictionariesDTO> listDict = dictDAO.getDictionaries();
		for (DictionariesDTO dictionariesDTO : listDict) {
			LanguagesDTO fromDTO = lanDAO.getLanguage(dictionariesDTO.getFrom());
			LanguagesDTO toDTO = lanDAO.getLanguage(dictionariesDTO.getTo());
			try {
				out.print("<option value="+
						dictionariesDTO.getId()+
						">"+fromDTO.getName()+" - "+toDTO.getName()+"</option>");
			} catch (IOException e) {
				
			}
		}
		return (SKIP_BODY);
	}
	
}
